import { userlist,usercount } from '@/request/api'
export default{
    state:{
        userList:[],
        size:2,
        page:1,
        count:0
    },
    mutations:{
        mutation_userList(state,payload){
            state.userList = payload
        },
        mutation_count(state,payload){
            state.count = payload
        },
        mutation_page(state,payload){
            state.page = payload
        }
    },
    // 获取数据
    getters:{
        get_userList(state){
            return state.userList
        },
        get_count(state){
            return state.count
        },
        get_size(state){
            return state.size
        }
    },
    // 异步操作，请求数据
    actions:{
        async action_userList({commit,state},payload){
            try{
                let  res = await userlist({page:state.page,size:state.size});
                if(res.code==200){
                    // console.log(res);
                    commit('mutation_userList',res.list)
                }
            }catch(err){
                console.log(err);
            }
        },
        async action_userconut({commit},payload){
            try{
                let  res = await usercount();
                if(res.code==200){
                    // console.log(res.list[0].total);
                    commit('mutation_count',res.list[0].total)
                }
            }catch(err){
                console.log(err);
            }
        }
    },
    namespaced:true
}